<template>
  <div id="app">
    <div class="loading" v-if="loading">
      <van-loading type="spinner" color="#fff">加载中</van-loading>
    </div>

    <div style="width: 100%; padding: 10px 5%; z-index: 1" class="content">
      <div class="text">{{ pubName }}</div>

      <div style="margin-top: 20px">
        <div style="padding: 15px; background: hsl(0deg 0% 100% / 60%); font-size: 14px; font-weight: 600">
          <div style="margin: 0px auto 10px; font-size: 16px; font-weight: 900">江南布衣+内购券</div>
          <van-row class="row" type="flex" justify="space-between" style="margin-bottom: 10px">
            <van-col :span="6"> 有效时间： </van-col>
            <van-col :span="16" style="text-align: left">
              {{ time }}
            </van-col>
          </van-row>
          <van-row class="row" type="flex" justify="space-between" style="margin-bottom: 10px">
            <van-col :span="6"> 使用店铺： </van-col>
            <van-col :span="16" style="text-align: left; font-size: 12px">
              {{ store }}
            </van-col>
          </van-row>
          <van-row class="row" type="flex" justify="space-between" style="margin-bottom: 10px">
            <van-col :span="6"> 使用规则： </van-col>
            <van-col :span="16" style="text-align: left; font-size: 12px">
              {{ role }}
            </van-col>
          </van-row>
          <div @click="loadData">
            <svg class="barcode" jsbarcode-format="CODE128" :jsbarcode-value="barcode" jsbarcode-textmargin="0" jsbarcode-fontoptions="bold"></svg>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script src="https://www.jq22.com/jquery/vue.min.js"></script>
<script src='js/JsBarcode.all.min.js'></script>
<script>
import JsBarcode from 'jsbarcode'

export default {
  name: 'home',
  data() {
    return {
      type: this.$route.query.type,
      pubName: '',
      id: '',
      time: '',
      store: '',
      loading: true,
      role: '1、本券适用于公司总部全体正式员工;2、本券为员工福利，仅限本人使用，不得转增他人;3、本券的条码信息，每60秒自动刷新;4、本券仅限当月有效，逾期作废;',
      barcode: ''
    }
  },
  computed: {
    linkid() {
      return localStorage.getItem('linkid')
    }
  },
  created: function () {
    document.title = '员工福利'
  },
  mounted() {
    this.loadData()
    this.id = setInterval(() => {
      setTimeout(() => {
        this.loadData()
      }, 0)
    }, 60000)
  },
  destroyed() {
    clearInterval(this.id)
  },
  methods: {
    loadData() {
      this.$http({
        url: '/api/gateway/basemgt-purchase/purchase/brand',
        method: 'get',
        params: {
          linkid: this.linkid,
          // linkid:192,
          brandType: this.type
        }
      }).then(data => {
        if (data.code == 200) {
          ;(this.pubName = data.data.pubName), (this.time = data.data.globalDateTimeNow), (this.store = data.data.storeName), (this.barcode = data.data.barcode)
          this.$nextTick(() => {
            JsBarcode('.barcode').init()
          })
        } else {
          this.$toast(data.msg)
        }
        this.loading = false
      })
    }
  }
}
</script>
<style scoped>
#app {
  height: 100vh;
  background-image: url('./bg.jpg');
  text-align: center;
  color: #2c3e50;
}
.content {
  background-image: url('./bg.jpg');
}
.text {
  display: block;
  font-size: 30px;
  text-align: center;
}
.title {
  height: 60px;
  background: #dcdee0;
  line-height: 60px;
  margin-bottom: 100px;
}
.loading {
  position: fixed;
  z-index: 9999;
  width: 100%;
  height: 100%;
  background: #323233ba;
  display: flex;
  justify-content: center;
  align-items: center;
}
.custom-image .van-empty__image {
  width: 90px;
  height: 90px;
}
.barcode {
  width: 100%;
}
</style>